/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package RemoteDesktop;

import StaticClass.ArrSocket;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Oho
 */
public class ConnectRemote extends Thread {

    Socket sk;
    int port;
    Robot robot;
    Rectangle rectangle;

    public ConnectRemote(int port) {
        try {
            this.port = port;
            GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice gDev = gEnv.getDefaultScreenDevice();
            Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
            rectangle = new Rectangle(dim);
            robot = new Robot(gDev);
        } catch (AWTException ex) {
            Logger.getLogger(ConnectRemote.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    @Override
    public void run() {
        try {
            sk = new Socket(ArrSocket.HOSTNAME, port);
            new ThreadImages(sk,robot,rectangle).start();
            //ServerDelegate recieves server commands and execute them
           // new ServerDelegate(socket,robot);
            new ServerDelegate(sk, robot).start();
        } catch (UnknownHostException ex) {
            Logger.getLogger(ConnectRemote.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ConnectRemote.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
